<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>用户管理 - 管理后台</title>
    <link rel="stylesheet" href="/static/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all"/>
</head>
<body class="childrenBody">
<div class="layui-col-md12">
    <form class="layui-form " action="" method="get">
        <blockquote class="layui-elem-quote title">
            <span class="layui-breadcrumb">
                <a href="javascript:void(0);">用户管理</a>
                <a><cite>用户列表</cite></a>
            </span>
            <div class="layui-inline">
                <label class="layui-form-label">搜索</label>
                <div class="layui-input-inline">
                    <select name="admin_id" id="admin_id">
                        <option value="">选择业务员</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <input name="name" value="" class="layui-input" placeholder="请输入会员姓名/昵称"/>
                </div>
                <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">搜索</button>
            </div>
        </blockquote>
    </form>
    <table id="userList" lay-filter="userList" class="layui-table"></table>
    <script type="text/html" id="userListTBar">
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="order">已购买课程</a>
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="productOrder">已购买套餐</a>
    </script>
    <script type="text/html" id="userImage">
        <img src="{{ d.avatar }}" layer-src="{{ d.avatar }}" alt="{{ d.nickname }}" style="height:30px;"/>
    </script>
</div>
<script src="/static/layui.js"></script>
<script>
    layui.use(['element', 'jquery', 'layer', 'table', 'form'], function () {
        var element = layui.element,
            layer = layui.layer,
            $ = layui.jquery,
            table = layui.table,
            form = layui.form;
        $.get('{:url("admin/lists",["type"=>2])}', function (data) {
            var html = '<option value="">选择业务员</option>'
            $(data.data).each(function (i, e) {
                html += '<option value="' + e.admin_id + '">' + e.nickname + '</option>'
            });
            $('#admin_id').html(html);
            form.render('select');
        }, 'json');
        form.on('submit(demo1)', function (data) {
            table.reload('userListTable', {
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });
        layui.tableIns = table.render({
            elem: '#userList',
            url: '{:url("user/lists")}',
            cellMinWidth: 95,
            page: true,
            limit: 15,
            limits: [15, 20, 30, 50],
            id: "userListTable",
            cols: [[
                {field: 'nickname', title: '微信昵称', minWidth: 100, align: "center"},
                {field: 'avatar', templet: '#userImage', title: '头像', width: 100, align: "center"},
                {field: 'name', title: '姓名', width: 100, align: "center"},
                {field: 'phone', title: '电话', width: 200, align: "center"},
                {
                    field: 'sex', title: '性别', width: 100, align: "center", templet: function (d) {
                        return d.sex == 1 ? '男' : d.sex == 2 ? '女' : '未知';
                    }
                },
                {field: 'company', title: '公司名称', width: 300, align: "center"},
                {field: 'position', title: '职务', width: 200, align: "center"},
                {field: 'create_time', title: '关注时间', minWidth: 100, align: "center"},
                {title: '操作', templet: '#userListTBar', fixed: 'right', width: 250, align: 'center'}
            ]]
        });
        $('.childrenBody').on('click', 'img', function () {
            var img = new Array;
            img.push({src: $(this).attr('src')});
            layer.photos({
                photos: {data: img},
                anim: 5
            });
        });
        table.on('tool(userList)', function (obj) {
            var layEvent = obj.event,
                data = obj.data;
            if (layEvent === 'edit') {
                var index = layui.layer.open({
                    title: "编辑会员",
                    type: 2,
                    content: "{:url('user/editUser')}?id=" + data.user_id,
                    area: ['500px', '80%']
                });
            } else if (layEvent === 'order') {
                var index = layui.layer.open({
                    title: "已购买课程",
                    type: 2,
                    content: "{:url('user/userOrder')}?id=" + data.user_id,
                    area: ['80%', '80%']
                });
            } else if (layEvent === 'productOrder') {
                var index = layui.layer.open({
                    title: "已购买产品",
                    type: 2,
                    content: "{:url('user/userProductOrder')}?id=" + data.user_id,
                    area: ['80%', '80%']
                });
            }
        });
    });
</script>
</body>
</html>